<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="vue.js"></script>
    <title>Document</title>
    <style>
        table{
            border-collapse: collapse;
        }
        td,th{
            border: 1px solid black;
            width: 120px;
            text-align: center;
        }
    </style>
</head>
<body>
    <main id="app">
        <table>
            <tr>
                <td>商品名称</td>
                <td>商品价格</td>
                <td>商品数量</td>
                <td>操作</td>
            </tr>
            <tr v-for='(pin,index) in List'>
                <td>{{pin.name}}</td>
                <td>{{pin.price}}</td>
                <td is='first-com'></td>
                <td>
                    <button @click='remove(index)'>删除</button>
                </td>
            </tr>
        </table>
       <label for="">姓名:</label>
       <input type="text" v-model="message">
       <label for="">地址:</label>
       <input type="text" v-model="dizhi">
       <div>
        <h1>{{page}}</h1>
        <first-com :mypage='page' @pagechange="refrePage"></first-com>
        <h4 v-text="message"></h4>
        <h4 v-text="dizhi"></h4>
       </div>
    </main>
    <script>
        Vue.component('first-com',{
            template:`"
            <div>
                <button @click='preClick()'>-</button>
                <span>{{newPage}}</span>
                <button @click='nextClick()'>+</button>
            </div>"
            `,
            data:function(){
                return {
                    newPage:this.mypage
                }
            },
            props:{
                mypage:Number,
            },
            methods:{
                preClick:function(){
                    this.$emit('pagechange',-- this.newPage)
                },
                nextClick:function(){
                    this.$emit('pagechange',++ this.newPage)
                }
            }
        })
        var vue = new Vue({
            el:"#app",
            data:{
                page:1,
                List:[
                {name: '辣椒',price:1 ,count: '1' },
                {name: '泡椒鸡爪',price:1.5,count: '1'},
                {name: '巧克力',price:3,count: '1'}   
                ]
            },
            methods:{
                remove:function(index){
                    this.List.splice(index,1)
                },
                refrePage:function(value){
                    this.page = value
                }
            }
        })
    </script>
</body>
</html>